<?php
require_once("../connection.php");

$gpid = $_POST['gpid'];
$fbid = $_POST['fbid'];

// we'll check if any such row exists or nor
$temp1 = mysql_query("SELECT * FROM site_requests WHERE `gpid`='$gpid' AND `fbid`='$fbid'");
if(mysql_numrows($temp1)!=0){
$res = mysql_query("UPDATE site_requests SET `status`='1' WHERE `gpid`='$gpid' AND `fbid`='$fbid'");
if(!$res) echo mysql_error();
$id = mysql_result($temp1,0,'id');
}



// check if the user was already a member of this group before and was deleted. if yes, then just change the del parameter to 0
$temp1 = mysql_query("SELECT * FROM site_group_members WHERE `gpid`='$gpid' AND `fbid`='$fbid'");
if(mysql_numrows($temp1)==0){
	$res1 = mysql_query("INSERT INTO site_group_members (`gpid`,`fbid`,`mod`,`del`) VALUES('$gpid','$fbid','0','0')");
	if(!$res1) echo mysql_error();
}
else{
	$res1 = mysql_query("UPDATE site_group_members SET `del`='0' WHERE `gpid`='$gpid' AND `fbid`='$fbid'");
	if(!$res1) echo mysql_error();
}

//for the subscription thing
echo "id_accept_".$id;
?>